﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DataTransfer;
namespace Gui
{
    public partial class frmDanhSachCachDung : DevComponents.DotNetBar.Office2007Form
    {
        public CachDungBus cachdungBus;
        public frmDanhSachCachDung()
        {
            InitializeComponent();
        }

        private void frmDanhSachCachDung_Load(object sender, EventArgs e)
        {
            load();
        }
        public void load()
        {
            cachdungBus = new CachDungBus();
            dtgDanhSachCachDung.DataSource = cachdungBus.GetAll();
            dtgDanhSachCachDung.Columns["Pass"].Visible = false;
        }
        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnThemCachDung_Click(object sender, EventArgs e)
        {
            Form frm = new frmThemCachDung(this);
            frm.ShowDialog();
        }

        private void btnXoaCachDung_Click(object sender, EventArgs e)
        {
            CachDung info = new CachDung();
            getItem(ref info);
            cachdungBus = new CachDungBus();
            cachdungBus.Delele(info.ID);
            load();
        }

        private void btnSuaCachDung_Click(object sender, EventArgs e)
        {
            CachDung info = new CachDung();
            getItem(ref info);
            Form frm = new frmThemCachDung(this,info);
            frm.ShowDialog();
        }

        private bool getItem(ref CachDung info)
        {
            bool flag = false;
            int index = dtgDanhSachCachDung.CurrentRow.Index;
            if (index >= 0)
            {
                info.TenCachDung = dtgDanhSachCachDung["TenCachDung", index].Value.ToString();
                info.ID =Convert.ToInt32( dtgDanhSachCachDung["ID", index].Value.ToString());
                flag = true;
            }
            if (flag == false)
            {
                MessageBox.Show("Chua chon Item");
            }
            return flag;
        }
    }
}
